package com.sx.jys.ui.vm

import com.sx.jys.app.net.HttpRequestCoroutine
import com.sx.jys.app.net.bean.Code
import com.sx.jys.app.until.MutableLiveListData
import com.sx.jys.app.until.request2
import me.hgj.jetpackmvvm.base.viewmodel.BaseViewModel
import me.hgj.jetpackmvvm.callback.livedata.BooleanLiveData
import me.hgj.jetpackmvvm.callback.livedata.StringLiveData

class HomeVm : BaseViewModel() {
    val listLiveData = MutableLiveListData<Code>()

    val uiState = UIStateChange()

    inner class UIStateChange {
        val refreshEvent = BooleanLiveData()
        val yhField = StringLiveData()
        val orderField = StringLiveData()
        val rateField = StringLiveData()
    }

    fun reqHomeList(type: Int) {
        request2({ HttpRequestCoroutine.homeList(type) }, {
            uiState.yhField.value = it.todayProfit
            uiState.orderField.value = it.todayOrderNum
            uiState.rateField.value = it.chanceOfWinning
            listLiveData.value = it.codeList
            uiState.refreshEvent.postValue(true)
        }, isShowDialog = true)
    }
}